
function onBridgeReady (data) {
/* eslint-disable */
  WeixinJSBridge.invoke(
    'getBrandWCPayRequest', {
      'appId': data.appid,
      'timeStamp': data.stimeStamp,
      'nonceStr': data.nonceStr,
      'package': data.prepay_id,
      'signType': 'MD5',
      'paySign': data.sign
    },
    function (res) {
      if (res.err_msg === 'get_brand_wcpay_request:ok') {
        location.href = 'evcqtc.natappfree.cc/api/returnUrl?url=' + data.returnUrl + '&type=' + 1
      } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
        location.href = 'evcqtc.natappfree.cc/api/returnUrl?url=' + data.returnUrl + '&type=' + 2
      } else if (res.err_msg === 'get_brand_wcpay_request:fail') {
        location.href = 'evcqtc.natappfree.cc/api/returnUrl?url=' + data.returnUrl + '&type=' + 3
      }
    }
  )
}

export function openWXPay (data) {
  console.log(data)
  if (typeof WeixinJSBridge === 'undefined') {
    if (document.addEventListener) {
      document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
    } else if (document.attachEvent) {
      document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
      document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
    }
  } else {
    onBridgeReady(data)
  }
}
